package de.latzko.pattern.monteCarlo
import java.util.Random
import java.util.Random._
import de.latzko.pattern.math._
import de.latzko.pattern.math.NearestNeighbour
import scalala.tensor.dense.DenseVector._
import scalala.tensor.dense.DenseVector
import scalala.Scalala._
import scalala.Scalala
import scala.actors._
import Actor._

/**
 * 
 * @author tom
 *
 */
object SpmCluster {
  /**
   * 
   */
  def apply(mcSteps: Int, vectors: Array[DenseVector], qSpins: Int, knn: Int, sigma: Double = 0.5,
    tempSteps: Int = 200, deltaT: Double = 0.01) = {
    locateSpmPhase(mcSteps, vectors, qSpins, knn, sigma, tempSteps, deltaT)
  }

  def locateSpmPhase(mcSteps: Int, vectors: Array[DenseVector],
    qSpins: Int, knn: Int, sigma: Double,
    tempSteps: Int, deltaT: Double): DenseVector = {

    var susceptibility: DenseVector = DenseVector(tempSteps)(0)
    val caller = self
    for (i <- 0 until tempSteps) {
      actor {
        caller ! (i, magneticCalculation(mcSteps, vectors, qSpins, knn, i * deltaT))
      }
    }
    for (i <- 0 until tempSteps) {
      receive {
        case susc: (Int, Double) => susceptibility(susc._1) = susc._2
      }
    }
    susceptibility
  }

  def magneticCalculation(mcSteps: Int, vectors: Array[DenseVector],
    qSpins: Int, knn: Int, temp: Double) = {
    val nn = new Wolff(vectors, qSpins, knn)
    nn.runMethode(mcSteps, temp)
  }

  def computeCorrelation() = {

  }

  def labelData() = {

  }
}